<html>
<head>
<title>RoleController.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: #606366; font-weight: normal; font-style: normal; }
.s0 { color: rgb(204,120,50); }
.s1 { color: rgb(169,183,198); }
.s2 { color: rgb(106,135,89); }
.s3 { color: rgb(98,151,85); font-style: italic; }
.s4 { color: rgb(98,151,85); font-weight: bold; font-style: italic; }
.s5 { color: rgb(128,128,128); }
.s6 { color: rgb(104,151,187); }
</style>
</head>
<BODY BGCOLOR="#2b2b2b">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
RoleController.java</FONT>
</center></TD></TR></TABLE>
<pre>
<span class="s0">package </span><span class="s1">com.yxb.teaching_assessment.biz.controller</span><span class="s0">;</span><span class="s1"> 
 
</span><span class="s0">import </span><span class="s1">com.yxb.teaching_assessment.biz.entity.Role</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">com.yxb.teaching_assessment.biz.service.RoleService</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">com.yxb.teaching_assessment.biz.vo.AbstractBaseCtrl</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">com.yxb.teaching_assessment.biz.vo.ResultVO</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">io.swagger.annotations.Api</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">io.swagger.annotations.ApiOperation</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">org.springframework.beans.factory.annotation.Autowired</span><span class="s0">;</span><span class="s1"> 
</span><span class="s0">import </span><span class="s1">org.springframework.web.bind.annotation.*</span><span class="s0">;</span><span class="s1"> 
 
</span><span class="s0">import </span><span class="s1">java.util.List</span><span class="s0">;</span><span class="s1"> 
 
@RestController 
@Api(tags = </span><span class="s2">&quot;权限管理模块&quot;</span><span class="s1">) 
@RequestMapping(</span><span class="s2">&quot;/role&quot;</span><span class="s1">) 
</span><span class="s0">public class </span><span class="s1">RoleController </span><span class="s0">extends </span><span class="s1">AbstractBaseCtrl { 
    @Autowired 
    RoleService roleService</span><span class="s0">;</span><span class="s1"> 
 
    </span><span class="s3">/** 
     * 权限列表 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;/list&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;权限列表&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO roleList(){ 
        List&lt;Role&gt; roleList = roleService.roleList()</span><span class="s0">;</span><span class="s1"> 
        </span><span class="s0">return </span><span class="s1">success(roleList)</span><span class="s0">;</span><span class="s1"> 
    } 
 
    </span><span class="s3">/** 
     * 权限新增 
     * </span><span class="s4">@param </span><span class="s3">role 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;/save&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;新增权限&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO roleSave(@RequestBody Role role){ 
        </span><span class="s5">//数据校验</span><span class="s1"> 
        </span><span class="s0">if </span><span class="s1">(role==</span><span class="s0">null</span><span class="s1">){ 
            </span><span class="s0">return </span><span class="s1">error(</span><span class="s2">&quot;数据不存在&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
        }</span><span class="s0">else </span><span class="s1">{ 
            </span><span class="s5">//数据处理（新增操作）</span><span class="s1"> 
            </span><span class="s0">int </span><span class="s1">ret = roleService.saveRole(role)</span><span class="s0">;</span><span class="s1"> 
            </span><span class="s5">//新增是否成功</span><span class="s1"> 
            </span><span class="s0">if </span><span class="s1">(ret==</span><span class="s6">1</span><span class="s1">){ 
                </span><span class="s0">return </span><span class="s1">success(</span><span class="s2">&quot;权限新增成功&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
            }</span><span class="s0">else </span><span class="s1">{ 
                </span><span class="s0">return </span><span class="s1">error(</span><span class="s2">&quot;新增权限失败&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
            } 
        } 
    } 
 
    </span><span class="s3">/** 
     * 权限信息修改 
     * </span><span class="s4">@param </span><span class="s3">role 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;update&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;权限信息修改&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO updateRole(@RequestBody Role role){ 
        </span><span class="s0">int </span><span class="s1">ret = roleService.updateRole(role)</span><span class="s0">;</span><span class="s1"> 
        </span><span class="s0">return </span><span class="s1">success(</span><span class="s2">&quot;修改权限成功&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
    } 
 
    </span><span class="s3">/** 
     * 权限删除（逻辑删除） 
     * </span><span class="s4">@param </span><span class="s3">id 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;/delete&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;删除权限&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO deleteRole(@RequestParam(</span><span class="s2">&quot;roleid&quot;</span><span class="s1">)</span><span class="s0">int </span><span class="s1">id){ 
        </span><span class="s0">int </span><span class="s1">ret = roleService.deleteRole(id)</span><span class="s0">;</span><span class="s1"> 
        </span><span class="s0">if </span><span class="s1">(ret==</span><span class="s6">1</span><span class="s1">){ 
            </span><span class="s0">return </span><span class="s1">success(</span><span class="s2">&quot;删除权限成功&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
        }</span><span class="s0">else </span><span class="s1">{ 
            </span><span class="s0">return </span><span class="s1">error(</span><span class="s2">&quot;删除权限失败&quot;</span><span class="s1">)</span><span class="s0">;</span><span class="s1"> 
        } 
    } 
 
    </span><span class="s3">/** 
     * 根据id查找权限 
     * </span><span class="s4">@param </span><span class="s3">id 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;/role&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;根据id查找权限&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO findRoleById(@RequestParam(</span><span class="s2">&quot;roleid&quot;</span><span class="s1">)</span><span class="s0">int </span><span class="s1">id){ 
        Role role = roleService.findRoleById(id)</span><span class="s0">;</span><span class="s1"> 
        </span><span class="s0">return </span><span class="s1">success(role)</span><span class="s0">;</span><span class="s1"> 
    } 
 
    </span><span class="s3">/** 
     * 根据权限名称模糊查询权限列表 
     * </span><span class="s4">@param </span><span class="s3">rolename 
     * </span><span class="s4">@return</span><span class="s3"> 
     */</span><span class="s1"> 
    @PostMapping(</span><span class="s2">&quot;/roleLike&quot;</span><span class="s1">) 
    @ApiOperation(value = </span><span class="s2">&quot;根据权限名称模糊查找权限&quot;</span><span class="s1">) 
    </span><span class="s0">public </span><span class="s1">ResultVO findRoleByname(@RequestParam(</span><span class="s2">&quot;rolename&quot;</span><span class="s1">)String rolename){ 
        </span><span class="s0">if </span><span class="s1">(rolename==</span><span class="s0">null</span><span class="s1">){ 
            rolename=</span><span class="s2">&quot;&quot;</span><span class="s0">;</span><span class="s1"> 
        } 
        List&lt;Role&gt; roleList = roleService.findRoleByLikeName(rolename)</span><span class="s0">;</span><span class="s1"> 
        </span><span class="s0">return </span><span class="s1">success(roleList)</span><span class="s0">;</span><span class="s1"> 
    } 
} 
</span></pre>
</body>
</html>